from DjangoUeditor.models import UEditorField
from django.db import models


# Create your models here.
# class NewsPlate(models.Model):
#     name = models.CharField(max_length=200, verbose_name='板块名称')
#     tag = models.CharField(max_length=2, verbose_name='板块位置', unique=True, blank=True, null=True)




# 设置
#
# 多个公共设置项
class Modules(models.Model):
    """
    二级页面用的模板
    """
    name = models.CharField(max_length=10, verbose_name='模板名称')
    url = models.CharField(max_length=200, verbose_name='模板地址')

    def __str__(self):
        return str(self.name)

    class Meta:
        ordering = ('-pk',)
        verbose_name = '二级页面模板'
        verbose_name_plural = verbose_name


PLATE_SHOW = (('1', '校园新闻'), ('2', '公告通知'))


class Plates(models.Model):
    """
    二级板块
    """
    name = models.CharField(max_length=10, verbose_name='名称')
    module = models.ForeignKey(Modules, on_delete=models.CASCADE, verbose_name='模板', blank=True, null=True)
    image = models.FileField(upload_to='web_banner', verbose_name='banner图', blank=True, null=True)
    show_index = models.CharField(max_length=2, blank=True, null=True, unique=True, verbose_name='主页展示', default='0',
                                  choices=PLATE_SHOW)
    z_index = models.IntegerField(verbose_name='顺序', help_text=(
            '二级页面的排序，数字越大越靠后'
        ), default=0)

    def __str__(self):
        return str(self.name)

    class Meta:
        ordering = ('-pk',)
        verbose_name = '板块'
        verbose_name_plural = verbose_name


class Footer(models.Model):
    content = models.CharField(max_length=200, verbose_name='内容')

    def __str__(self):
        return str(self.content)

    class Meta:
        ordering = ('-pk',)
        verbose_name = '底部内容'
        verbose_name_plural = verbose_name


class SettingWeb(models.Model):
    name = models.CharField(max_length=20, verbose_name='说明')
    phone = models.CharField(max_length=12, verbose_name='联系号码', blank=True, null=True)
    icon = models.FileField(upload_to='web_banner', verbose_name='标题icon', blank=True, null=True)
    pic = models.FileField(upload_to='web_banner', verbose_name='banner或轮播', blank=True, null=True,help_text='尺寸建议1920x600<br>底部跳转logo，尺寸自行掌握，建议为5张图片')
    url = models.URLField(verbose_name='跳转地址', blank=True, null=True)

    def __str__(self):
        return str(self.name)

    class Meta:
        ordering = ('-pk',)
        verbose_name = '配置项'
        verbose_name_plural = verbose_name


# 主页
#
# 主页部分多个表

NEWS_TAG = (('0', '主页小轮播'), ('1', '二级页面左侧浮窗'))


class News(models.Model):
    name = models.CharField(max_length=10, verbose_name='名称')
    pic = models.FileField(upload_to='news_pic', verbose_name='对外图片', blank=True, null=True,
                           help_text='图片列表页，图片尺寸，300x160<br>首页轮播，建议219x148<br>板块banner建议1200x380')
    # content = models.TextField(verbose_name='内容', blank=True, null=True)
    image = models.FileField(upload_to='news_pic', verbose_name='新闻banner', blank=True, null=True,
                             help_text='展示在新闻顶部位置,尺寸建议1200x380')
    content = UEditorField(u'内容 ', width=800, height=300, toolbars="full",
                           imagePath="web_news_images/%(basename)s_%(datetime)s.%(extname)s",
                           filePath="web_news_files/%(basename)s_%(datetime)s.%(extname)s",
                           upload_settings={"imageMaxSize": 1204000}, blank=True, null=True)
    tag = models.CharField(max_length=2, verbose_name='板块位置', blank=True, null=True, choices=NEWS_TAG)
    belong_plate = models.ForeignKey(Plates, on_delete=models.CASCADE, verbose_name='所属模块', null=True, blank=True,
                                     related_name='has_news')
    up_time = models.DateTimeField(auto_now_add=True, verbose_name='新闻时间')

    def __str__(self):
        return str(self.name)

    class Meta:
        ordering = ('-pk',)
        verbose_name = '新闻'
        verbose_name_plural = verbose_name



